<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>数据代理</title>
</head>
<body>
  <script>
    let number = 20
    let person = {
      name: 'rose',
      sex: '1'
    }

    // proxy number with age
    Object.defineProperty(person, 'age', {
      // value: number,
      enumerable: true,
      // writable: true,
      configurable: true,
      get() {
        return number
      },
      set(value) {
        // write person.age = write number
        number = value
      }
    })

    Object.keys(person)
      .forEach(key => console.log(key))
    console.log(person)
  </script>
</body>
</html>